(function(Global /*, context */) {



    function OnAbilityChanged(event) {
        // $.Msg("OnAbilityChanged ",Abilities.GetAbilityName(event.entityIndex))
        var localHeroIndex = Players.GetPlayerHeroEntityIndex( Players.GetLocalPlayer());
        var abilityId=event.entityIndex;

        if(Abilities.GetAbilityName(abilityId)!=="ability_empty"&&Global.GameConfig) {
            // $.Msg("abilitycout..",Entities.GetAbilityCount( localHeroIndex))
            for (var i = 0; i <Global.GameConfig.abilitiesSlotCount+1;i++) {
                if (Entities.GetAbility(localHeroIndex, i) === abilityId) {
                    var abilityBg = Global.Panel.dotaHud.FindChildTraverse("Ability" + i)
                        if(abilityBg!==null){
                            abilityBg=abilityBg.FindChildTraverse("AbilityButton");
                        }
                    // $.Msg("OnAbilityChanged Btn=", abilityBg)
                    if (abilityBg === null) {
                        break
                    }
                    if (Abilities.GetAbilityType(abilityId) === ABILITY_TYPES.ABILITY_TYPE_ULTIMATE) {
                        abilityBg.style.backgroundColor = Global.Config.abilityUltBgColor;
                    }
                    else if ((Abilities.GetBehavior(abilityId) & DOTA_ABILITY_BEHAVIOR.DOTA_ABILITY_BEHAVIOR_PASSIVE) !== 0) {
                        abilityBg.style.backgroundColor = Global.Config.abilityAttrBgColor;
                    }
                    else {
                        abilityBg.style.backgroundColor = Global.Config.abilityBasicBgColor;
                    }
                    break;
                }
            }
        }
    }


    // GameEvents.Subscribe('dota_ability_changed', OnAbilityChanged);



})(GameUI.CustomUIConfig(), this);